// META: title=test WebNN API clamp operation
// META: global=window,dedicatedworker
// META: variant=?cpu
// META: variant=?gpu
// META: variant=?npu
// META: script=../resources/utils.js
// META: timeout=long

'use strict';

// https://www.w3.org/TR/webnn/#api-mlgraphbuilder-clamp
// Clamp the input tensor element-wise within a range specified by the minimum
// and maximum values.
//
// dictionary MLClampOptions {
//   MLNumber minValue;
//   MLNumber maxValue;
// };
//
// MLOperand clamp(MLOperand input, optional MLClampOptions options = {});


const getClampPrecisionTolerance = (graphResources) => {
  const toleranceValueDict = {float32: 0, float16: 0};
  const expectedDataType =
      getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs);
  return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]};
};

const clampTests = [
  {
    'name': 'clamp float32 1D constant tensor default options',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'},
          'constant': true
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'clamp float32 1D tensor default options',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'clamp float32 2D tensor default options',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [4, 6], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [4, 6], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'clamp float32 3D tensor default options',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'clamp float32 4D tensor default options',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [3, 2, 2, 2], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [3, 2, 2, 2], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'clamp float32 5D tensor default options',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [4, 1, 1, 2, 3], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [4, 1, 1, 2, 3], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 4D tensor default options.maxValue and specified negative options.minValue',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [2, 1, 4, 3], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}, {'options': {'minValue': -1}}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -1,
            -1,
            -1,
            -1,
            -1,
            9.524681091308594,
            3.7292487621307373,
            6.481687068939209,
            -1,
            -1,
            7.880751132965088,
            -1,
            6.3438639640808105,
            5.525737762451172,
            0.8433118462562561,
            -1,
            -1,
            9.280223846435547,
            -1,
            9.549695014953613,
            5.788925647735596,
            5.549378395080566,
            7.409400463104248,
            -1
          ],
          'descriptor': {'dimensions': [2, 1, 4, 3], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 3D tensor default options.maxValue and specified options.minValue=0.0',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [6, 2, 2], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 0}}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            0,
            0,
            0,
            0,
            0,
            9.524681091308594,
            3.7292487621307373,
            6.481687068939209,
            0,
            0,
            7.880751132965088,
            0,
            6.3438639640808105,
            5.525737762451172,
            0.8433118462562561,
            0,
            0,
            9.280223846435547,
            0,
            9.549695014953613,
            5.788925647735596,
            5.549378395080566,
            7.409400463104248,
            0
          ],
          'descriptor': {'dimensions': [6, 2, 2], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 2D tensor default options.maxValue and specified positive options.minValue',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [3, 8], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}, {'options': {'minValue': 1}}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            1,
            1,
            1,
            1,
            1,
            9.524681091308594,
            3.7292487621307373,
            6.481687068939209,
            1,
            1,
            7.880751132965088,
            1,
            6.3438639640808105,
            5.525737762451172,
            1,
            1,
            1,
            9.280223846435547,
            1,
            9.549695014953613,
            5.788925647735596,
            5.549378395080566,
            7.409400463104248,
            1
          ],
          'descriptor': {'dimensions': [3, 8], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 5D tensor default options.minValue and specified negative options.maxValue',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [2, 2, 1, 2, 3], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': -2}}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,
            -6.024064064025879,
            -4.0725626945495605,
            -6.575078010559082,
            -7.755683898925781,
            -2,
            -2,
            -2,
            -2,
            -7.34310245513916,
            -2,
            -2.0564088821411133,
            -2,
            -2,
            -2,
            -8.199960708618164,
            -7.786487102508545,
            -2,
            -2.3130595684051514,
            -2,
            -2,
            -2,
            -2,
            -2.123614549636841
          ],
          'descriptor': {'dimensions': [2, 2, 1, 2, 3], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 1D tensor default options.minValue and specified options.maxValue=0.0',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': 0}}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,
            -6.024064064025879,
            -4.0725626945495605,
            -6.575078010559082,
            -7.755683898925781,
            0,
            0,
            0,
            -1.537420630455017,
            -7.34310245513916,
            0,
            -2.0564088821411133,
            0,
            0,
            0,
            -8.199960708618164,
            -7.786487102508545,
            0,
            -2.3130595684051514,
            0,
            0,
            0,
            0,
            -2.123614549636841
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 3D tensor default options.minValue and specified positive options.maxValue',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [3, 4, 2], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [{'input': 'clampInput'}, {'options': {'maxValue': 3}}],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -9.817828178405762,
            -6.024064064025879,
            -4.0725626945495605,
            -6.575078010559082,
            -7.755683898925781,
            3,
            3,
            3,
            -1.537420630455017,
            -7.34310245513916,
            3,
            -2.0564088821411133,
            3,
            3,
            0.8433118462562561,
            -8.199960708618164,
            -7.786487102508545,
            3,
            -2.3130595684051514,
            3,
            3,
            3,
            3,
            -2.123614549636841
          ],
          'descriptor': {'dimensions': [3, 4, 2], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 5D tensor specified both negative options.minValue and options.maxValue',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [3, 2, 1, 1, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [
          {'input': 'clampInput'}, {'options': {'minValue': -8, 'maxValue': -1}}
        ],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -8,
            -6.024064064025879,
            -4.0725626945495605,
            -6.575078010559082,
            -7.755683898925781,
            -1,
            -1,
            -1,
            -1.537420630455017,
            -7.34310245513916,
            -1,
            -2.0564088821411133,
            -1,
            -1,
            -1,
            -8,
            -7.786487102508545,
            -1,
            -2.3130595684051514,
            -1,
            -1,
            -1,
            -1,
            -2.123614549636841
          ],
          'descriptor': {'dimensions': [3, 2, 1, 1, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 4D tensor specified negative options.minValue and options.maxValue=0.0',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [1, 4, 3, 2], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [
          {'input': 'clampInput'}, {'options': {'minValue': -6, 'maxValue': 0}}
        ],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -6,
            -6,
            -4.0725626945495605,
            -6,
            -6,
            0,
            0,
            0,
            -1.537420630455017,
            -6,
            0,
            -2.0564088821411133,
            0,
            0,
            0,
            -6,
            -6,
            0,
            -2.3130595684051514,
            0,
            0,
            0,
            0,
            -2.123614549636841
          ],
          'descriptor': {'dimensions': [1, 4, 3, 2], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 3D tensor specified negative options.minValue and positive options.maxValue',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [2, 6, 2], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [
          {'input': 'clampInput'}, {'options': {'minValue': -3, 'maxValue': 4}}
        ],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            -3,
            -3,
            -3,
            -3,
            -3,
            4,
            3.7292487621307373,
            4,
            -1.537420630455017,
            -3,
            4,
            -2.0564088821411133,
            4,
            4,
            0.8433118462562561,
            -3,
            -3,
            4,
            -2.3130595684051514,
            4,
            4,
            4,
            4,
            -2.123614549636841
          ],
          'descriptor': {'dimensions': [2, 6, 2], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 2D tensor specified options.minValue=0.0 and positive options.maxValue',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [6, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [
          {'input': 'clampInput'}, {'options': {'minValue': 0, 'maxValue': 6}}
        ],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            0,
            0,
            0,
            0,
            0,
            6,
            3.7292487621307373,
            6,
            0,
            0,
            6,
            0,
            6,
            5.525737762451172,
            0.8433118462562561,
            0,
            0,
            6,
            0,
            6,
            5.788925647735596,
            5.549378395080566,
            6,
            0
          ],
          'descriptor': {'dimensions': [6, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'clamp float32 1D tensor specified both positive options.minValue and options.maxValue',
    'graph': {
      'inputs': {
        'clampInput': {
          'data': [
            -9.817828178405762,  -6.024064064025879, -4.0725626945495605,
            -6.575078010559082,  -7.755683898925781, 9.524681091308594,
            3.7292487621307373,  6.481687068939209,  -1.537420630455017,
            -7.34310245513916,   7.880751132965088,  -2.0564088821411133,
            6.3438639640808105,  5.525737762451172,  0.8433118462562561,
            -8.199960708618164,  -7.786487102508545, 9.280223846435547,
            -2.3130595684051514, 9.549695014953613,  5.788925647735596,
            5.549378395080566,   7.409400463104248,  -2.123614549636841
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'clamp',
        'arguments': [
          {'input': 'clampInput'}, {'options': {'minValue': 2, 'maxValue': 7}}
        ],
        'outputs': 'clampOutput'
      }],
      'expectedOutputs': {
        'clampOutput': {
          'data': [
            2,
            2,
            2,
            2,
            2,
            7,
            3.7292487621307373,
            6.481687068939209,
            2,
            2,
            7,
            2,
            6.3438639640808105,
            5.525737762451172,
            2,
            2,
            2,
            7,
            2,
            7,
            5.788925647735596,
            5.549378395080566,
            7,
            2
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      }
    }
  }
];

if (navigator.ml) {
  clampTests.forEach((test) => {
    webnn_conformance_test(
        buildGraphAndCompute, getClampPrecisionTolerance, test);
  });
} else {
  test(() => assert_implements(navigator.ml, 'missing navigator.ml'));
}
